home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ für Kids
/
C++ for kids.iso
/
Buch
/
Roller1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-25
|
5KB
|
173 lines
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include "Roller1.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
class TChassis
{
protected:
int x1, x2, y1, y2;
int Breite, Hoehe, Diff;
public:
TChassis (int X, int Y, int B);
virtual ~TChassis (void);
virtual void Show (void);
// hier steht die rein virtuelle Methode
virtual void Move (int Ziel) = 0;
};
class TVelo : public TChassis
{
public:
TVelo (int X, int Y, int B);
virtual void Show (void);
// hier wird die rein virtuelle Methode ⁿberschrieben
virtual void Move (int Ziel) {};
};
class TAuto : public TChassis
{
public:
TAuto (int X, int Y, int B);
virtual void Show (void);
// hier wird die rein virtuelle Methode ⁿberschrieben
virtual void Move (int Ziel) {};
};
TAuto *Auto;
TVelo *Velo;
TForm1 *Form1;
//---------------------------------------------------------------------------
TChassis::TChassis (int X, int Y, int B)
{
x1 = X;
y1 = Y;
Breite = B;
Hoehe = Breite/2;
x2 = x1 + Breite;
y2 = y1 + Hoehe;
Diff = Breite/5;
}
//---------------------------------------------------------------------------
TChassis::~TChassis (void)
{
}
//---------------------------------------------------------------------------
TVelo::TVelo (int X, int Y, int B)
: TChassis (X, Y, B)
{
}
//---------------------------------------------------------------------------
TAuto::TAuto (int X, int Y, int B)
: TChassis (X, Y, B)
{
}
//---------------------------------------------------------------------------
void TChassis::Show (void)
{
int Dicke = Breite/3;
int Felge = Dicke/6;
// nur die beiden RΣder zeichnen
Form1->Canvas->Pen->Width = 2;
Form1->Canvas->Brush->Color = clInactiveCaption;
Form1->Canvas->Ellipse (x1,y2-Dicke,x1+Dicke,y2);
Form1->Canvas->Ellipse (x2-Dicke,y2-Dicke,x2,y2);
Form1->Canvas->Brush->Color = clActiveCaption;
Form1->Canvas->Ellipse
(x1+Felge,y2-Dicke+Felge,x1+Dicke-Felge,y2-Felge);
Form1->Canvas->Ellipse
(x2-Dicke+Felge,y2-Dicke+Felge,x2-Felge,y2-Felge);
}
//---------------------------------------------------------------------------
void TVelo::Show (void)
{
int Radius = Breite/6;
Form1->Refresh ();
// Fahrgestell zeichnen
TChassis::Show ();
// Rahmen zeichnen
Form1->Canvas->Pen->Width = 4;
Form1->Canvas->MoveTo (x1+Radius,y2-Radius);
Form1->Canvas->LineTo (x1+2*Radius,y1+Diff/3);
Form1->Canvas->LineTo (x1+3*Radius,y2-Radius);
Form1->Canvas->LineTo (x2-2*Radius,y1+Diff/3);
Form1->Canvas->LineTo (x2-Radius,y2-Radius);
Form1->Canvas->MoveTo (x1+2*Radius,y1+Diff/3);
Form1->Canvas->LineTo (x2-2*Radius,y1+Diff/3);
// Lenker und Tretkurbel zeichnen
Form1->Canvas->Arc
(x2-2*Radius-Diff/2,y1,x2-2*Radius+Diff/2,y1+Diff/3,
x2-2*Radius,y1+Diff/3,x2-2*Radius,y1);
Form1->Canvas->MoveTo (x1+3*Radius,y1+Radius+2*Diff/5);
Form1->Canvas->LineTo (x1+3*Radius,y1+Radius+6*Diff/5);
// Sattel und Pedale zeichnen
Form1->Canvas->Pen->Width = 1;
Form1->Canvas->Brush->Color = clActiveCaption;
Form1->Canvas->Ellipse
(x1+2*Radius-Diff/2,y1,x1+2*Radius+Diff/2,y1+Diff/3);
Form1->Canvas->Rectangle
(x1+3*Radius-Diff/5,y1+Radius+Diff/5,
x2-3*Radius+Diff/5,y1+Radius+2*Diff/5);
Form1->Canvas->Rectangle
(x1+3*Radius-Diff/5,y1+Radius+6*Diff/5,
x2-3*Radius+Diff/5,y1+Radius+7*Diff/5);
}
//---------------------------------------------------------------------------
void TAuto::Show (void)
{
int Radius = Breite/6;
Form1->Refresh ();
// Karosserie zeichnen
Form1->Canvas->Pen->Width = 1;
Form1->Canvas->Brush->Color = clActiveCaption;
Form1->Canvas->RoundRect
(x1,y1+Breite/6-5,x2,y2-Diff/3, 30,30);
// Fahrgestell zeichnen
TChassis::Show ();
Form1->Canvas->Pen->Width = 4;
Form1->Canvas->MoveTo (x1+Diff/4,y1+Breite/6);
Form1->Canvas->LineTo (x2-Diff/4,y1+Breite/6);
// Tⁿr und Fenster zeichnen
Form1->Canvas->Pen->Width = 1;
Form1->Canvas->RoundRect
(x1+2*Radius+5,y1,x2-2*Radius-5,y2-Diff/3,20,20);
Form1->Canvas->Pen->Width = 2;
Form1->Canvas->Brush->Color = clInactiveCaption;
Form1->Canvas->RoundRect
(x1+2*Radius+10,y1+10,x2-2*Radius-10,y1+Breite/4,20,20);
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Auto= new TAuto (60,20,310);
Velo= new TVelo (60,20,310);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Velo->Show ();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Auto->Show ();
}
//---------------------------------------------------------------------------